import request from '@/utils/request';

//图片上传接口
export function uploadImage(params) {
    return request({
        url: '/v1/image/upload',
        method: 'POST',
        data: params,
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        transformRequest: [
            function(data, headers) {
                const formData = new FormData();
                for (const key of Object.keys(data)) {
                    if (key === 'files') {
                        for (var i = 0; i < data[key].length; i++) {
                            for (const key2 of Object.keys(data[key][i])) {
                                formData.append(`files[${i}].${key2}`, data[key][i][key2]);
                            }
                        }
                    } else {
                        formData.append(key, data[key]);
                    }
                }
                return formData;
            }
        ]
    });
}

//查询所有图片分组
export function queryAllImageGroup() {
    return request({
        url: '/v1/image/group/queryall',
        method: 'GET'
    });
}

//查询图片信息列表
export function queryConditionList(params) {
    return request({
        url: '/v1/image/query/list/condition',
        method: 'POST',
        data: params
    });
}

//创建图片分组接口
export function createImageGroup(params) {
    return request({
        url: '/v1/image/group/create',
        method: 'PUT',
        data: params
    });
}

//更新图片分组接口
export function updateImageGroup(params) {
    return request({
        url: '/v1/image/group/update',
        method: 'POST',
        data: params
    });
}

//批量删除图片接口
export function batchDeleteImage(params) {
    return request({
        url: '/v1/image/delete/batch',
        method: 'DELETE',
        data: params
    });
}

//批量删除图片接口
export function deleteImage(params) {
    return request({
        url: '/v1/image/delete/' + params.id,
        method: 'DELETE'
    });
}

//修改图片文件名称接口
export function updateImageName(params) {
    return request({
        url: '/v1/image/update/name',
        method: 'POST',
        data: params
    });
}

//将某图片移动至某分组下
export function moveToImage(params) {
    return request({
        url: '/v1/image/moveto',
        method: 'POST',
        data: params
    });
}

//删除分组
export function deleteImageGroup(params) {
    return request({
        url: '/v1/image/group/delete/' + params.id,
        method: 'DELETE'
    });
}

// 获取所有系统链接
export function querySurlType(params) {
    return request({
        url: '/v1/app/surl/query/type/' + params.type,
        method: 'GET'
    });
}
